package cn.itcast.transport;

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.TransportAddress;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @Description TODO :
 * @Author: zj
 * @Date: 15:49 2019/3/7
 * @Version 1.0
 **/
public class TestTransportClient {

    public static void main(String[] args) {
        TransportClient client = null;
        try {
            //添加集群名称
            Settings settings = Settings.builder().put("cluster.name","elasticsearch").build();
            client = new PreBuiltTransportClient(settings)
                    .addTransportAddress(new TransportAddress(InetAddress.getByName("192.168.217.128"), 9200));
            System.out.println(client + "连接成功");
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } finally {
            client.close();
        }



    }
}
